﻿using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.Tools
{
    public class Utiy
    {
        /// <summary>
        /// 增加Page页
        /// </summary>
        /// <param name="form"></param>
        /// <param name="tabControl1"></param>
        /// <param name="name"></param>
        public static void AddPage(UserControl form,TabControl tabControl1,string name)
        {
            TabPage tabPage = new TabPage();
            tabPage.Tag = form; 

            tabPage.Text = name;
            tabPage.Name = name;

            form.Parent = tabPage;
            form.Dock = DockStyle.Fill;

            tabPage.Controls.Add(form);
            tabControl1.TabPages.Add(tabPage);
            //使创建出来的窗口得到焦点
            tabControl1.SelectTab(tabPage);
            form.Show();
        }
        /// <summary>
        /// 增加Page页
        /// </summary>
        /// <param name="form"></param>
        /// <param name="tabControl1"></param>
        /// <param name="name"></param>
        public static void AddPage(Form form,TabPage tabPage)
        {
            tabPage.Tag = form;
            form.TopLevel = false;
            form.Parent = tabPage;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = DockStyle.Fill;
            tabPage.Controls.Add(form);
            form.Show();
        }
        /// <summary>
        /// 删除Page页
        /// </summary>
        /// <param name="tabControl1"></param>
        /// <param name="name"></param>
        public static void RemovePage(TabControl tabControl1, string name)
        {
            TabPage tabPage = null;
            foreach (TabPage item in tabControl1.TabPages)
            {
                if (item.Name == name)
                {
                    tabPage = item;
                }
            }
            if (tabPage != null)
            {
                tabControl1.TabPages.Remove(tabPage);
            }
        }
        /// <summary>
        /// 打开颜色提取器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void OpenColorDir(Object sender, EventArgs e)
        {
            ColorDialog dlg = new ColorDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string str = dlg.Color.ToString();
                if (!str.Contains('='))
                {
                    str = str.Substring(str.IndexOf('[') + 1, (str.IndexOf(']', str.IndexOf('[')) - str.IndexOf('[')) - 1);
                    (sender as TextBox).Tag = dlg.Color;
                    (sender as TextBox).Text = str;
                }
                else
                {
                    (FormDb.Db["Form1"] as Form1).textBox1.AppendText("该软件不支持RGB!\r\n");
                }
            }
        }

    }
}
